<!DOCTYPE html>
<html lang='en'>
<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script type='text/javascript' src='js/vue.js'></script>
</head>
<body>
    <div id='app'>
        {{msg}}
        <p v-color='mycolor' v-bgcolor="pcol">hello world!</p>
    </div>
    <script type='text/javascript'>
        //自定义指令，主要是用 inserted  钩子函数
        Vue.directive('color', {
            inserted(el,binding) {
                console.log(el,binding,binding.value);  
                el.style.backgroundColor = binding.value;
            }
        });
        var vm = new Vue({
            el: '#app',
            data: {
                msg: 'Hello Vue',
                mycolor: 'pink',
                pcol: 'yellowgreen'
            },
            methods: {},
            //自定义局部指定
            directives: {
                bgcolor: {
                    inserted(el,binding) {
                        console.log(el,binding,binding.value);  
                        el.style.color = binding.value;
                    }
                }
            }
        });
    </script>
</body>
</html>